# Replication file
# EVS models in "Fixed Effects and Post-Treatment Bias in Legacy Studies"

rm(list=ls())
library(stargazer)

evs<-read.csv('evs.csv',stringsAsFactors = T)

# # # # # # # # # # # # # # # # # # # # # # # # # #
# # # Baseline G-estimator models in HPT 2020
# # # # # # # # # # # # # # # # # # # # # # # # # #

#%#%#%#% Outgroup intolerance

#1st stage
m1f<-lm(intolerance~Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+west,evs)

#2nd stage
m1s<-lm(I(intolerance - 
            coef(m1f)['immigrants07']*immigrants07 -
            coef(m1f)['lr']*lr -
            coef(m1f)['unemp']*unemp - 
            coef(m1f)['unemployment07']*unemployment07 - 
            coef(m1f)['educ']*educ -
            coef(m1f)['urban_scale']*urban_scale) ~ 
          Distance+
          prop_jewish25+
          unemployment33+
          population25+
          nazishare33, evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  #G-estimator 1st stage
  boot.first <- lm(intolerance~
                     Distance+
                     prop_jewish25+
                     unemployment33+
                     population25+
                     nazishare33+
                     #Post-treatment
                     lr+ 
                     immigrants07+
                     unemployment07+
                     unemp+
                     educ+
                     female+
                     age+
                     urban_scale+
                     west,
                   d.star)
  #G-estimator 2nd stage
  boot.direct <- lm(I(intolerance - 
                        coef(boot.first)['immigrants07']*immigrants07 -
                        coef(boot.first)['lr']*lr -
                        coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - 
                        coef(boot.first)['educ']*educ -
                        coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+
                      prop_jewish25+
                      unemployment33+
                      population25+
                      nazishare33,
                    d.star)
  fl.boots[b,] <- coef(boot.direct)
}
SEs1 <- apply(fl.boots,2,sd)


#%#%#%#% Immigrant resentment
#G-est 1st stage
m2f<-lm(resentment~Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+west,evs)

#G-est 2nd stage
m2s<-lm(I(resentment - 
            coef(m2f)['immigrants07']*immigrants07 -
            coef(m2f)['lr']*lr -
            coef(m2f)['unemp']*unemp - 
            coef(m2f)['unemployment07']*unemployment07 - 
            coef(m2f)['educ']*educ -
            coef(m2f)['urban_scale']*urban_scale) ~ 
          Distance+
          prop_jewish25+
          unemployment33+
          population25+
          nazishare33, evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(resentment~Distance+
                     prop_jewish25+
                     unemployment33+
                     population25+
                     nazishare33+
                     #Post-treatment
                     lr+
                     immigrants07+
                     unemployment07+
                     unemp+
                     educ+
                     female+
                     age+
                     urban_scale+
                     west,d.star)
  boot.direct <- lm(I(resentment - 
                        coef(boot.first)['immigrants07']*immigrants07 -
                        coef(boot.first)['lr']*lr -
                        coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - 
                        coef(boot.first)['educ']*educ -
                        coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+
                      prop_jewish25+
                      unemployment33+
                      population25+
                      nazishare33, d.star)
  fl.boots[b,] <- coef(boot.direct)
}
SEs2 <- apply(fl.boots,2,sd)

#%#%#%#% Far-right support
#G-est 1st stage
m3f<-lm(far_right~Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+west,evs)

#G-est 2nd stage
m3s<-lm(I(far_right - 
            coef(m3f)['immigrants07']*immigrants07 -
            coef(m3f)['lr']*lr -
            coef(m3f)['unemp']*unemp - 
            coef(m3f)['unemployment07']*unemployment07 - 
            coef(m3f)['educ']*educ -
            coef(m3f)['urban_scale']*urban_scale) ~ 
          Distance+
          prop_jewish25+
          unemployment33+
          population25+
          nazishare33, evs)

#Full G-estimator
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(far_right~Distance+
                     prop_jewish25+
                     unemployment33+
                     population25+
                     nazishare33+
                     #Post-treatment
                     lr+ 
                     immigrants07+
                     unemployment07+
                     unemp+
                     educ+
                     female+
                     age+
                     urban_scale+
                     west,d.star)
  boot.direct <- lm(I(far_right - 
                        coef(boot.first)['immigrants07']*immigrants07 -
                        coef(boot.first)['lr']*lr -
                        coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - 
                        coef(boot.first)['educ']*educ -
                        coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+
                      prop_jewish25+
                      unemployment33+
                      population25+
                      nazishare33, d.star)
  fl.boots[b,] <- coef(boot.direct)
}
#Extracting bootstrapped SEs
SEs3 <- apply(fl.boots,2,sd)

#Storing coefs/SEs for coefficient plots
cfs_baseline<-c(coef(m1s)[2], coef(m2s)[2], coef(m3s)[2])
ses_baseline<-c(SEs1[2],SEs2[2],SEs3[2])


# # # # # # # # # # # # # # # # # # # # # # # # # #
# # # Models with contemporary states FEs in 1st stage
# # # # # # # # # # # # # # # # # # # # # # # # # #

#%#%#%#% Outgorup intolerance
#1st stage
m1f<-lm(intolerance~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(state),evs)
#2nd stage
m1s<-lm(I(intolerance - 
            coef(m1f)['immigrants07']*immigrants07 - coef(m1f)['lr']*lr - coef(m1f)['unemp']*unemp -  
            coef(m1f)['unemployment07']*unemployment07 - coef(m1f)['educ']*educ - coef(m1f)['urban_scale']*urban_scale) ~ 
          Distance+prop_jewish25+unemployment33+population25+nazishare33, evs)

#bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(intolerance~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(state),
                   d.star)
  boot.direct <- lm(I(intolerance - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33,
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs <- apply(fl.boots,2,sd)


#%#%#%#% Immigrant resentment
#1st stage
m2f<-lm(resentment~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(state),evs)
#2nd stage
m2s<-lm(I(resentment - 
            coef(m2f)['immigrants07']*immigrants07 - coef(m2f)['lr']*lr - coef(m2f)['unemp']*unemp -  
            coef(m2f)['unemployment07']*unemployment07 - coef(m2f)['educ']*educ - coef(m2f)['urban_scale']*urban_scale) ~ 
          Distance+prop_jewish25+unemployment33+population25+nazishare33, evs)

#bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(resentment~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(state),
                   d.star)
  boot.direct <- lm(I(resentment - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33,
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs2 <- apply(fl.boots,2,sd)



#%#%#%#% Far-right support
#1st stage
m3f<-lm(far_right~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(state),evs)

#2nd stage
m3s<-lm(I(far_right - 
            coef(m3f)['immigrants07']*immigrants07 - coef(m3f)['lr']*lr - coef(m3f)['unemp']*unemp -  
            coef(m3f)['unemployment07']*unemployment07 - coef(m3f)['educ']*educ - coef(m3f)['urban_scale']*urban_scale) ~ 
          Distance+prop_jewish25+unemployment33+population25+nazishare33, evs)

#bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(far_right~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(state),
                   d.star)
  boot.direct <- lm(I(far_right - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33,
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs3 <- apply(fl.boots,2,sd)

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
#Table SM4.1
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
stargazer(m1f,m1s,m2f,m2s,m3f,m3s, se=list(NULL,SEs,NULL,SEs2,NULL,SEs3),dep.var.labels.include = FALSE,
          no.space=T, covariate.labels = c('Distance to camp', '\\% Jews (1925)',
                                           '\\% Unemployed (1933)', 'Population (1925)', 'Nazi party share (1933)'),
          star.cutoffs = c(0.05, 0.01, NA))

#Storing coefs/SEs for coefficient plots
cfs_currentstates_1st<-c(coef(m1s)[2], coef(m2s)[2], coef(m3s)[2])
ses_currentstates_1st<-c(SEs[2],SEs2[2],SEs3[2])



# # # # # # # # # # # # # # # # # # # # # # # # # #
# # # Models with Weimar-era states' FEs
# # # # # # # # # # # # # # # # # # # # # # # # # #

#%#%#%#% Outgroup intolerance
#OLS
m1_2<-lm(intolerance~Distance+prop_jewish25+unemployment33+population25+nazishare33+as.factor(Weimar_states_fromcentroids),evs)

#G-est 1st stage
m1f<-lm(intolerance~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(Weimar_states_fromcentroids),evs)

#G-est 2nd stage
m1s<-lm(I(intolerance - 
            coef(m1f)['immigrants07']*immigrants07 - coef(m1f)['lr']*lr - coef(m1f)['unemp']*unemp -  
            coef(m1f)['unemployment07']*unemployment07 - coef(m1f)['educ']*educ - coef(m1f)['urban_scale']*urban_scale) ~ 
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          as.factor(Weimar_states_fromcentroids), evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(intolerance~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_fromcentroids),
                   d.star)
  boot.direct <- lm(I(intolerance - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_fromcentroids),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs <- apply(fl.boots,2,sd)


#%#%#%#% Immigrant resentment
#OLS
m2_2<-lm(resentment~Distance+prop_jewish25+unemployment33+population25+nazishare33+as.factor(Weimar_states_fromcentroids),evs)

#G-est 1st stage
m2f<-lm(resentment~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(Weimar_states_fromcentroids),evs)

#G-est 2nd stage
m2s<-lm(I(resentment - 
            coef(m2f)['immigrants07']*immigrants07 - coef(m2f)['lr']*lr - coef(m2f)['unemp']*unemp -  
            coef(m2f)['unemployment07']*unemployment07 - coef(m2f)['educ']*educ - coef(m2f)['urban_scale']*urban_scale) ~ 
          Distance+
          prop_jewish25+
          unemployment33+
          population25+
          nazishare33+as.factor(Weimar_states_fromcentroids), evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(resentment~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_fromcentroids),
                   d.star)
  boot.direct <- lm(I(resentment - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_fromcentroids),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs2 <- apply(fl.boots,2,sd)


#%#%#%#% Far-right support
#OLS
m3_2<-lm(far_right~Distance+prop_jewish25+unemployment33+population25+nazishare33+as.factor(Weimar_states_fromcentroids),evs)

#G-est 1st stage
m3f<-lm(far_right~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(Weimar_states_fromcentroids),evs)

#G-est 2nd stage
m3s<-lm(I(far_right - 
            coef(m3f)['immigrants07']*immigrants07 - coef(m3f)['lr']*lr - coef(m3f)['unemp']*unemp -  
            coef(m3f)['unemployment07']*unemployment07 - coef(m3f)['educ']*educ - coef(m3f)['urban_scale']*urban_scale) ~ 
          Distance+
          prop_jewish25+
          unemployment33+
          population25+
          nazishare33+as.factor(Weimar_states_fromcentroids), evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(far_right~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_fromcentroids),
                   d.star)
  boot.direct <- lm(I(far_right - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_fromcentroids),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs3 <- apply(fl.boots,2,sd)


#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
#TABLE SM4.2
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
stargazer(m1_2,m1s,m2_2,m2s,m3_2,m3s, se=list(NULL,SEs,NULL,SEs2,NULL,SEs3),dep.var.labels.include = FALSE,
          no.space=T, covariate.labels = c('Distance to camp', '\\% Jews (1925)',
                                           '\\% Unemployed (1933)', 'Population (1925)', 'Nazi party share (1933)'),
          star.cutoffs = c(0.05, 0.01, NA))

#Storing coefs and SEs for coef plot
cfs_weimar_centroid<-c(coef(m1s)[2], coef(m2s)[2], coef(m3s)[2])
ses_weimar_centroid<-c(SEs[2],SEs2[2],SEs3[2])
cfs_ols_weimar_centroid<-c(coef(m1_2)[2], coef(m2_2)[2], coef(m3_2)[2])
ses_ols_weimar_centroid<-c(sqrt(vcov(m1_2)[2,2]),sqrt(vcov(m2_2)[2,2]),sqrt(vcov(m3_2)[2,2]))



# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # Models with Weimar-era states' FEs and Contemp. states in 1st stage
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

#%#%#%#% Outgroup intolerance
#G-est 1st stage
m1f<-lm(intolerance~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+as.factor(state)+
          as.factor(Weimar_states_fromcentroids),evs)

#G-est 2nd stage
m1s<-lm(I(intolerance - 
            coef(m1f)['immigrants07']*immigrants07 - coef(m1f)['lr']*lr - coef(m1f)['unemp']*unemp -  
            coef(m1f)['unemployment07']*unemployment07 - coef(m1f)['educ']*educ - coef(m1f)['urban_scale']*urban_scale) ~ 
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          as.factor(Weimar_states_fromcentroids), evs)

#Bootsrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(intolerance~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_fromcentroids)+as.factor(state),
                   d.star)
  boot.direct <- lm(I(intolerance - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_fromcentroids),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}

SEs <- apply(fl.boots,2,sd)


#%#%#%#% Immigrant resentment
#G-est 1st stage
m2f<-lm(resentment~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(Weimar_states_fromcentroids)+as.factor(state),evs)

#G-est 2nd stage
m2s<-lm(I(resentment - 
            coef(m2f)['immigrants07']*immigrants07 - coef(m2f)['lr']*lr - coef(m2f)['unemp']*unemp -  
            coef(m2f)['unemployment07']*unemployment07 - coef(m2f)['educ']*educ - coef(m2f)['urban_scale']*urban_scale) ~ 
          Distance+
          prop_jewish25+
          unemployment33+
          population25+
          nazishare33+as.factor(Weimar_states_fromcentroids), evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(resentment~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_fromcentroids)+as.factor(state),
                   d.star)
  boot.direct <- lm(I(resentment - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_fromcentroids),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs2 <- apply(fl.boots,2,sd)


#%#%#%#% Far-right support
#G-est 1st stage
m3f<-lm(far_right~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(Weimar_states_fromcentroids)+as.factor(state),evs)

#G-est 2nd stage
m3s<-lm(I(far_right - 
            coef(m3f)['immigrants07']*immigrants07 - coef(m3f)['lr']*lr - coef(m3f)['unemp']*unemp -  
            coef(m3f)['unemployment07']*unemployment07 - coef(m3f)['educ']*educ - coef(m3f)['urban_scale']*urban_scale) ~ 
          Distance+
          prop_jewish25+
          unemployment33+
          population25+
          nazishare33+as.factor(Weimar_states_fromcentroids), evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(far_right~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_fromcentroids)+as.factor(state),
                   d.star)
  boot.direct <- lm(I(far_right - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_fromcentroids),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs3 <- apply(fl.boots,2,sd)

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
#TABLE SM4.3
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
stargazer(m1f,m1s,m2f,m2s,m3f,m3s, se=list(NULL,SEs,NULL,SEs2,NULL,SEs3),dep.var.labels.include = FALSE,
          no.space=T, covariate.labels = c('Distance to camp', '\\% Jews (1925)',
                                           '\\% Unemployed (1933)', 'Population (1925)', 'Nazi party share (1933)'),
          star.cutoffs = c(0.05, 0.01, NA))

#Storing cfs and SEs for coefficient plots
cfs_weimar_centroid_and_contemp<-c(coef(m1s)[2], coef(m2s)[2], coef(m3s)[2])
ses_weimar_centroid_and_contemp<-c(SEs[2],SEs2[2],SEs3[2])


# # # # # # # # # # # 
# # # # # # # # # # # 
# Figure 5 - COEF PLOTS
# # # # # # # # # # # 
# # # # # # # # # # # 

#### OUTGROUP INTOLERANCE
cfs<-c(cfs_baseline[1], #baseline g-est
       cfs_currentstates_1st[1], #g-est with current states in 1st stage
       cfs_weimar_centroid[1], #g-est with weimar states based on centroids
       cfs_weimar_centroid_and_contemp[1]) #g-est with weimar states based on centroids and including Saarland
sts<-round(c(ses_baseline[1],
             ses_currentstates_1st[1],
             ses_weimar_centroid[1],
             ses_weimar_centroid_and_contemp[1]),3)

pdf('evs_coefplot1.pdf', width=6.25, height=4.2)
par(mar=c(4.5,12,2,2))
plot(seq(-.03,.01, length.out = 2), c(.5,4.5), type='n',yaxt='n', ylab='',
     xlab='Controlled direct effect of distance\non Outgroup Intolerance',cex.lab=.9)
abline(v=0,lty=2)
pos<-1:4
axis(side= 2,at=rev(pos),labels=c('Baseline', 'Current state FEs\nin 1st stage',
                                  'Weimar state FEs\n(centroid interpolation)',
                                  'Current state FEs\n+ Weimar state FEs'),las=2,tick=F, cex.axis=.9)
points(cfs,rev(pos),pch=20)
for (i in 1:4){
  segments(cfs[i]-1.96*sts[i],rev(pos)[i],
           cfs[i]+1.96*sts[i])
  segments(cfs[i]-1.65*sts[i],rev(pos)[i],
           cfs[i]+1.65*sts[i], lwd=2)
}
dev.off()


#### IMMIGRANT RESENTMENT
cfs<-c(cfs_baseline[2], #baseline g-est
       cfs_currentstates_1st[2], #g-est with current states in 1st stage
       cfs_weimar_centroid[2], #g-est with weimar states based on centroids
       cfs_weimar_centroid_and_contemp[2]) #g-est with weimar states based on centroids and including Saarland
sts<-round(c(ses_baseline[2],
             ses_currentstates_1st[2],
             ses_weimar_centroid[2],
             ses_weimar_centroid_and_contemp[2]),3)

pdf('evs_coefplot2.pdf', width=4.3, height=4.2)
par(mar=c(4.5,2,2,2))
plot(seq(-.18,.05, length.out = 2), c(.5,4.5), type='n',yaxt='n', ylab='',
     xlab='Controlled direct effect of distance\non Immigrant Resentment',cex.lab=.9)
abline(v=0,lty=2)
pos<-1:4
points(cfs,rev(pos),pch=20)
for (i in 1:4){
  segments(cfs[i]-1.96*sts[i],rev(pos)[i],
           cfs[i]+1.96*sts[i])
  segments(cfs[i]-1.65*sts[i],rev(pos)[i],
           cfs[i]+1.65*sts[i], lwd=2)
}
dev.off()


#### FAR-RIGHT SUPPORT
cfs<-c(cfs_baseline[3], #baseline g-est
       cfs_currentstates_1st[3], #g-est with current states in 1st stage
       cfs_weimar_centroid[3], #g-est with weimar states based on centroids
       cfs_weimar_centroid_and_contemp[3]) #g-est with weimar states based on centroids and including Saarland
sts<-round(c(ses_baseline[3],
             ses_currentstates_1st[3],
             ses_weimar_centroid[3],
             ses_weimar_centroid_and_contemp[3]),3)

pdf('evs_coefplot3.pdf', width=4.3, height=4.2)
par(mar=c(4.5,2,2,2))
plot(seq(-.005,.001, length.out = 2), c(.5,4.5), type='n',yaxt='n', ylab='',
     xlab='Controlled direct effect of distance\non Support for Far-Right Parties',cex.lab=.9)
abline(v=0,lty=2)
pos<-1:4
points(cfs,rev(pos),pch=20)
for (i in 1:4){
  segments(cfs[i]-1.96*sts[i],rev(pos)[i],
           cfs[i]+1.96*sts[i])
  segments(cfs[i]-1.65*sts[i],rev(pos)[i],
           cfs[i]+1.65*sts[i], lwd=2)
}
dev.off()


##%#%#%#%#%#%#%#%#%##%#%#%#%#%#%#%#%#%##%#%#%#%#%#%#%#%#%
# # # # Figure SM4.1 ##%#%#%#%#%#%#%#%#%##%#%#%#%#%#%#%#%
##%#%#%#%#%#%#%#%#%##%#%#%#%#%#%#%#%#%##%#%#%#%#%#%#%#%#%

###########################################
#%#%#%#%#%#% MODELS WITH CENTROID INT + SAARLAND
###########################################

#%#%#%#% Outgroup intolerance with alternative centroid interpolation

#G-est 1st stage
m1f<-lm(intolerance~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(Weimar_states_fromcentroids_v2),evs)

#G-est 2nd stage
m1s<-lm(I(intolerance - 
            coef(m1f)['immigrants07']*immigrants07 - coef(m1f)['lr']*lr - coef(m1f)['unemp']*unemp -  
            coef(m1f)['unemployment07']*unemployment07 - coef(m1f)['educ']*educ - coef(m1f)['urban_scale']*urban_scale) ~ 
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          as.factor(Weimar_states_fromcentroids_v2), evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(intolerance~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_fromcentroids_v2),
                   d.star)
  boot.direct <- lm(I(intolerance - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_fromcentroids_v2),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs <- apply(fl.boots,2,sd)


#%#%#%#% Immigrant resentment with alternative centroid interpolation

#G-est 1st stage
m2f<-lm(resentment~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(Weimar_states_fromcentroids_v2),evs)

#G-est 2nd stage
m2s<-lm(I(resentment - 
            coef(m2f)['immigrants07']*immigrants07 - coef(m2f)['lr']*lr - coef(m2f)['unemp']*unemp -  
            coef(m2f)['unemployment07']*unemployment07 - coef(m2f)['educ']*educ - coef(m2f)['urban_scale']*urban_scale) ~ 
          Distance+
          prop_jewish25+
          unemployment33+
          population25+
          nazishare33+as.factor(Weimar_states_fromcentroids_v2), evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(resentment~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_fromcentroids_v2),
                   d.star)
  boot.direct <- lm(I(resentment - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_fromcentroids_v2),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs2 <- apply(fl.boots,2,sd)


#%#%#%#% Far-right support with alternative centroid interpolation

#G-est 1st stage
m3f<-lm(far_right~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(Weimar_states_fromcentroids_v2),evs)

#G-est 2nd stage
m3s<-lm(I(far_right - 
            coef(m3f)['immigrants07']*immigrants07 - coef(m3f)['lr']*lr - coef(m3f)['unemp']*unemp -  
            coef(m3f)['unemployment07']*unemployment07 - coef(m3f)['educ']*educ - coef(m3f)['urban_scale']*urban_scale) ~ 
          Distance+
          prop_jewish25+
          unemployment33+
          population25+
          nazishare33+as.factor(Weimar_states_fromcentroids_v2), evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(far_right~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_fromcentroids_v2),
                   d.star)
  boot.direct <- lm(I(far_right - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_fromcentroids_v2),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs3 <- apply(fl.boots,2,sd)


#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
#Regression table with models estimated to produce coefficients reported Figure SM4.1 (Centroid interpolation + Saarland) 
  #Reported in dataverse appendix
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
# stargazer(m1f,m1s,m2f,m2s,m3f,m3s, se=list(NULL,SEs,NULL,SEs2,NULL,SEs3),dep.var.labels.include = FALSE,
#           no.space=T, covariate.labels = c('Distance to camp', '\\% Jews (1925)',
#           '\\% Unemployed (1933)', 'Population (1925)', 'Nazi party share (1933)'),
#           star.cutoffs = c(0.05, 0.01, NA))

#Storing coefs and SEs for coef plot
cfs_weimar_centroid_v2<-c(coef(m1s)[2], coef(m2s)[2], coef(m3s)[2])
ses_weimar_centroid_v2<-c(SEs[2],SEs2[2],SEs3[2])

###########################################
#%#%#%#%#%#% MODELS WITH AREA INTERPOLATION
###########################################

#%#%#%#% Outgroup intolerance with area interpolation

#G-est 1st stage
m1f<-lm(intolerance~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(Weimar_states_area),evs)

#G-est 2nd stage
m1s<-lm(I(intolerance - 
            coef(m1f)['immigrants07']*immigrants07 - coef(m1f)['lr']*lr - coef(m1f)['unemp']*unemp -  
            coef(m1f)['unemployment07']*unemployment07 - coef(m1f)['educ']*educ - coef(m1f)['urban_scale']*urban_scale) ~ 
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          as.factor(Weimar_states_area), evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(intolerance~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_area),
                   d.star)
  boot.direct <- lm(I(intolerance - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_area),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs <- apply(fl.boots,2,sd)


#%#%#%#% Immigrant resentment with area interpolation

#G-est 1st stage
m2f<-lm(resentment~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(Weimar_states_area),evs)

#G-est 2nd stage
m2s<-lm(I(resentment - 
            coef(m2f)['immigrants07']*immigrants07 - coef(m2f)['lr']*lr - coef(m2f)['unemp']*unemp -  
            coef(m2f)['unemployment07']*unemployment07 - coef(m2f)['educ']*educ - coef(m2f)['urban_scale']*urban_scale) ~ 
          Distance+
          prop_jewish25+
          unemployment33+
          population25+
          nazishare33+as.factor(Weimar_states_area), evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(resentment~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_area),
                   d.star)
  boot.direct <- lm(I(resentment - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_area),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs2 <- apply(fl.boots,2,sd)


#%#%#%#% Far-right support with area interpolation

#G-est 1st stage
m3f<-lm(far_right~
          Distance+prop_jewish25+unemployment33+population25+nazishare33+
          #Post-treatment
          lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
          +as.factor(Weimar_states_area),evs)

#G-est 2nd stage
m3s<-lm(I(far_right - 
            coef(m3f)['immigrants07']*immigrants07 - coef(m3f)['lr']*lr - coef(m3f)['unemp']*unemp -  
            coef(m3f)['unemployment07']*unemployment07 - coef(m3f)['educ']*educ - coef(m3f)['urban_scale']*urban_scale) ~ 
          Distance+
          prop_jewish25+
          unemployment33+
          population25+
          nazishare33+as.factor(Weimar_states_area), evs)

#Bootstrapped SEs
boots <- 1000
set.seed(543)
fl.boots <- matrix(NA, nrow=boots, ncol=6)
for(b in 1:boots){
  d.star <- evs[sample(1:nrow(evs), replace=TRUE),]
  boot.first <- lm(far_right~
                     Distance+prop_jewish25+unemployment33+population25+nazishare33+
                     #Post-treatment
                     lr+immigrants07+unemployment07+unemp+educ+female+age+urban_scale+
                     +as.factor(Weimar_states_area),
                   d.star)
  boot.direct <- lm(I(far_right - 
                        coef(boot.first)['immigrants07']*immigrants07 - coef(boot.first)['lr']*lr - coef(boot.first)['unemp']*unemp - 
                        coef(boot.first)['unemployment07']*unemployment07 - coef(boot.first)['educ']*educ - coef(boot.first)['urban_scale']*urban_scale) ~ 
                      Distance+prop_jewish25+unemployment33+population25+nazishare33+
                      as.factor(Weimar_states_area),
                    d.star)
  fl.boots[b,] <- coef(boot.direct)[1:6]
}
SEs3 <- apply(fl.boots,2,sd)


#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
#Regression table with models estimated to produce coefficients reported Figure SM4.1 (Area interpolation) 
#Reported in dataverse appendix
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
# stargazer(m1f,m1s,m2f,m2s,m3f,m3s, se=list(NULL,SEs,NULL,SEs2,NULL,SEs3),dep.var.labels.include = FALSE,
#           no.space=T, covariate.labels = c('Distance to camp', '\\% Jews (1925)',
#           '\\% Unemployed (1933)', 'Population (1925)', 'Nazi party share (1933)'),
#           star.cutoffs = c(0.05, 0.01, NA))

#Storing coefs and SEs for coef plot
cfs_weimar_area<-c(coef(m1s)[2], coef(m2s)[2], coef(m3s)[2])
ses_weimar_area<-c(SEs[2],SEs2[2],SEs3[2])


############################
# Coefplots in Figure SM4.1
############################

# Panel a - Outgroup intolerance
cfs<-c(cfs_weimar_centroid[1],
       cfs_weimar_centroid_v2[1],
       cfs_weimar_area[1])
sts<-round(c(ses_weimar_centroid[1],
             ses_weimar_centroid_v2[1],
             ses_weimar_area[1]),3)

pdf('evs_interpolations1.pdf', width=6.25, height=4.2)
par(mar=c(4.5,12,2,2))
plot(seq(-.03,.01, length.out = 2), c(.5,3.5), type='n',yaxt='n', ylab='',
     xlab='Controlled direct effect of distance\non Outgroup Intolerance',cex.lab=.9)
abline(v=0,lty=2)
pos<-1:3
axis(side= 2,at=rev(pos),labels=c('Centroid interpolation',
                                  'Centroid interpolation\n+ Saarland',
                                  'Area interpolation'),las=2,tick=F, cex.axis=.9)
points(cfs,rev(pos),pch=20)
for (i in 1:3){
  segments(cfs[i]-1.96*sts[i],rev(pos)[i],
           cfs[i]+1.96*sts[i])
  segments(cfs[i]-1.65*sts[i],rev(pos)[i],
           cfs[i]+1.65*sts[i], lwd=2)
}
dev.off()

# Panel b - Immigrant resentment
cfs<-c(cfs_weimar_centroid[2],
       cfs_weimar_centroid_v2[2],
       cfs_weimar_area[2])
sts<-round(c(ses_weimar_centroid[2],
             ses_weimar_centroid_v2[2],
             ses_weimar_area[2]),3)

pdf('evs_interpolations2.pdf', width=4.3, height=4.2)
par(mar=c(4.5,2,2,2))
plot(seq(-.18,.05, length.out = 2), c(.5,3.5), type='n',yaxt='n', ylab='',
     xlab='Controlled direct effect of distance\non Immigrant Resentment',cex.lab=.9)
abline(v=0,lty=2)
pos<-1:3
points(cfs,rev(pos),pch=20)
for (i in 1:3){
  segments(cfs[i]-1.96*sts[i],rev(pos)[i],
           cfs[i]+1.96*sts[i])
  segments(cfs[i]-1.65*sts[i],rev(pos)[i],
           cfs[i]+1.65*sts[i], lwd=2)
}
dev.off()


#Panel c - Far-right support
cfs<-c(cfs_weimar_centroid[3],
       cfs_weimar_centroid_v2[3],
       cfs_weimar_area[3])
sts<-round(c(ses_weimar_centroid[3],
             ses_weimar_centroid_v2[3],
             ses_weimar_area[3]),3)

pdf('evs_interpolations3.pdf', width=4.3, height=4.2)
par(mar=c(4.5,2,2,2))
plot(seq(-.005,.001, length.out = 2), c(.5,3.5), type='n',yaxt='n', ylab='',
     xlab='Controlled direct effect of distance\non Support for Far-Right Parties',cex.lab=.9)
abline(v=0,lty=2)
pos<-1:3
points(cfs,rev(pos),pch=20)
for (i in 1:3){
  segments(cfs[i]-1.96*sts[i],rev(pos)[i],
           cfs[i]+1.96*sts[i])
  segments(cfs[i]-1.65*sts[i],rev(pos)[i],
           cfs[i]+1.65*sts[i], lwd=2)
}
dev.off()

##%#%#%#%#%#%#%#%#%##%#%#%#%#%#%#%#%#%##%#%#%#%#%#%#%#%#%
# # # # Figure SM4.2 ##%#%#%#%#%#%#%#%#%##%#%#%#%#%#%#%#%
##%#%#%#%#%#%#%#%#%##%#%#%#%#%#%#%#%#%##%#%#%#%#%#%#%#%#%

#Baseline
m1_1<-lm(intolerance~Distance+prop_jewish25+unemployment33+population25+nazishare33,evs)
m2_1<-lm(resentment~Distance+prop_jewish25+unemployment33+population25+nazishare33,evs)
m3_1<-lm(far_right~Distance+prop_jewish25+unemployment33+population25+nazishare33,evs)

#Models with alternative interpolation method (centroids with Saarland as separate state)
m1_2<-lm(intolerance~Distance+prop_jewish25+unemployment33+population25+nazishare33+as.factor(Weimar_states_fromcentroids_v2),evs)
m2_2<-lm(resentment~Distance+prop_jewish25+unemployment33+population25+nazishare33+as.factor(Weimar_states_fromcentroids_v2),evs)
m3_2<-lm(far_right~Distance+prop_jewish25+unemployment33+population25+nazishare33+as.factor(Weimar_states_fromcentroids_v2),evs)

#Storing coefs and SEs
cfs_ols_weimar_centroid_v2<-c(coef(m1_2)[2], coef(m2_2)[2], coef(m3_2)[2])
ses_ols_weimar_centroid_v2<-c(sqrt(vcov(m1_2)[2,2]),sqrt(vcov(m2_2)[2,2]),sqrt(vcov(m3_2)[2,2]))

#Models with area interpolation method
m1_3<-lm(intolerance~Distance+prop_jewish25+unemployment33+population25+nazishare33+as.factor(Weimar_states_area),evs)
m2_3<-lm(resentment~Distance+prop_jewish25+unemployment33+population25+nazishare33+as.factor(Weimar_states_area),evs)
m3_3<-lm(far_right~Distance+prop_jewish25+unemployment33+population25+nazishare33+as.factor(Weimar_states_area),evs)

#Storing coefs and SEs
cfs_ols_weimar_area<-c(coef(m1_3)[2], coef(m2_3)[2], coef(m3_3)[2])
ses_ols_weimar_area<-c(sqrt(vcov(m1_3)[2,2]),sqrt(vcov(m2_3)[2,2]),sqrt(vcov(m3_3)[2,2]))

#Panel a - Outgroup intolerance
cfs<-c(coef(m1_1)[2], #baseline ols
       cfs_ols_weimar_area[1], #ols with weimar states based on areal overlap
       cfs_ols_weimar_centroid[1], #ols with weimar states based on centroids
       cfs_ols_weimar_centroid_v2[1]) #ols with weimar states based on centroids and including Saarland
sts<-round(c(sqrt(vcov(m1_1)[2,2]),
             ses_ols_weimar_area[1],
             ses_ols_weimar_centroid[1],
             ses_ols_weimar_centroid_v2[1]),3)

par(mar=c(4.5,12,2,2))
plot(seq(-.025,.01, length.out = 2), c(.5,4.5), type='n',yaxt='n', ylab='',
     xlab='Marginal effect of distance\non Outgroup Intolerance',cex.lab=.9)
abline(v=0,lty=2)
pos<-1:4
axis(side= 2,at=rev(pos),labels=c('Baseline',
                                  'Weimar state FEs\n(area interpolation)', 
                                  'Weimar state FEs\n(centroid interpolation)',
                                  'Weimar state FEs\n(centroid interpolation) + Saarland'),las=2,tick=F, cex.axis=.8)
points(cfs,rev(pos),pch=20)
for (i in 1:4){
  segments(cfs[i]-1.96*sts[i],rev(pos)[i],
           cfs[i]+1.96*sts[i])
  segments(cfs[i]-1.65*sts[i],rev(pos)[i],
           cfs[i]+1.65*sts[i], lwd=2)
}


#Panel b - Immigrant resentment
cfs<-c(coef(m2_1)[2], #baseline ols
       cfs_ols_weimar_area[2], #ols with weimar states based on areal overlap
       cfs_ols_weimar_centroid[2], #ols with weimar states based on centroids
       cfs_ols_weimar_centroid_v2[2]) #ols with weimar states based on centroids and including Saarland
sts<-round(c(sqrt(vcov(m2_1)[2,2]),
             ses_ols_weimar_area[2],
             ses_ols_weimar_centroid[2],
             ses_ols_weimar_centroid_v2[2]),3)

par(mar=c(4.5,2,2,2))
plot(seq(-.18,.05, length.out = 2), c(.5,4.5), type='n',yaxt='n', ylab='',
     xlab='Marginal effect of distance\non Immigrant Resentment',cex.lab=.9)
abline(v=0,lty=2)
pos<-1:4
points(cfs,rev(pos),pch=20)
for (i in 1:4){
  segments(cfs[i]-1.96*sts[i],rev(pos)[i],
           cfs[i]+1.96*sts[i])
  segments(cfs[i]-1.65*sts[i],rev(pos)[i],
           cfs[i]+1.65*sts[i], lwd=2)
}


#Panel c - Far-right support
cfs<-c(coef(m3_1)[2], #baseline ols
       cfs_ols_weimar_area[3], #g-est with weimar states based on areal overlap
       cfs_ols_weimar_centroid[3], #g-est with weimar states based on centroids
       cfs_ols_weimar_centroid_v2[3]) #g-est with weimar states based on centroids and including Saarland
sts<-c(sqrt(vcov(m3_1)[2,2]),
       ses_ols_weimar_area[3],
       ses_ols_weimar_centroid[3],
       ses_ols_weimar_centroid_v2[3])

par(mar=c(4.5,2,2,2))
plot(seq(-.004,.002, length.out = 2), c(.5,4.5), type='n',yaxt='n', ylab='',
     xlab='Marginal effect of distance\non Support for Far-Right Parties',cex.lab=.9)
abline(v=0,lty=2)
pos<-1:4
points(cfs,rev(pos),pch=20)
for (i in 1:4){
  segments(cfs[i]-1.96*sts[i],rev(pos)[i],
           cfs[i]+1.96*sts[i])
  segments(cfs[i]-1.65*sts[i],rev(pos)[i],
           cfs[i]+1.65*sts[i], lwd=2)
}

#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
#Regression table with models estimated to produce coefficients reported Figure SM4.2 (centroid + Saarland) 
#Reported in dataverse appendix
#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
 # stargazer(m1_2,m2_2,m3_2, dep.var.labels.include = FALSE,
 #           no.space=T, covariate.labels = c('Distance to camp', '\\% Jews (1925)',
 #           '\\% Unemployed (1933)', 'Population (1925)', 'Nazi party share (1933)'),
 #           star.cutoffs = c(0.05, 0.01, NA))

 #%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
 #Regression table with models estimated to produce coefficients reported Figure SM4.2 (area interpolation) 
 #Reported in dataverse appendix
 #%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%#%
# stargazer(m1_3,m2_3,m3_3, dep.var.labels.include = FALSE,
#           no.space=T, covariate.labels = c('Distance to camp', '\\% Jews (1925)',
#                                            '\\% Unemployed (1933)', 'Population (1925)', 'Nazi party share (1933)'),
#           star.cutoffs = c(0.05, 0.01, NA))
 